home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / xlmath10.zip / XLMINIT.C < prev    next >
C/C++ Source or Header  |  1992-03-14  |  3KB  |  109 lines

  1. /*******************************************************************
  2.  
  3.  XLMINIT.C
  4.  
  5.  Author:    Roy Kari
  6.              Dept. of Chemistry
  7.             Laurentian University
  8.             Sudbury, Ont.
  9.             Canada        P3E 2C6
  10.             (705) 675-1151
  11.             Internet: "ROY@NICKEL.LAURENTIAN.CA"
  12.  
  13.   ***************************************************************** */
  14.  
  15. /* --------------------------< Include files >--------------------- */
  16.  
  17. #include <windows.h>
  18. #include "xlmopti.h"
  19. #include "xlmath.h"
  20. #include "xlmutil.h"
  21.  
  22. /* -----------------------< global variables >--------------------- */
  23.  
  24. OMEM_POOL ReturnPool;
  25. OMEM_POOL ScratchPool;
  26.  
  27. TD TaskDescriptors[MAX_TASK_DESC];
  28. HANDLE hLibInst;
  29. char *szLibName = "XLMATH.DLL";    // used by ErrorHandler
  30.  
  31. /* -------------------<Windows Entry & Exit Routines>-------------- */
  32.  
  33. /*********************************************************************
  34.  LibMain()
  35.  =========
  36.  This is the standard windows DLL entry routine. This allocates
  37.  a task descriptor in the local heap.
  38.  ********************************************************************/
  39. BOOL PASCAL FAR _export LibMain(HANDLE hInstance, WORD wDataSegment,
  40.     WORD wHeapSize, LPSTR CommandLine)
  41. {
  42.  
  43.     WORD wCount = MAX_TASK_DESC;
  44.     NPTD pTaskDesc = &TaskDescriptors[0];
  45.  
  46.     if (wHeapSize > 0)
  47.         UnlockData(0);
  48.  
  49.     // init task descriptors
  50.     while (wCount--)
  51.     {
  52.         pTaskDesc->hTask = NULL;
  53.         pTaskDesc->lpReturnBuffer = NULL;
  54.     }
  55.     // init shared memory pools
  56.     ReturnPool = MemPoolInit(TRUE);
  57.     ScratchPool = MemPoolInit(TRUE);
  58.     hLibInst = hInstance;
  59.  
  60.     return (1);
  61. }
  62. /*********************************************************************
  63.  WEP()
  64.  =====
  65.  This function is the standard windows DLL exit routine
  66.  ********************************************************************/
  67. int PASCAL FAR _export WEP(int bSystemExit)
  68. {
  69.     return (0);
  70. }
  71.  
  72. /* -----------------------<DLL Routines>--------------------------- */
  73.  
  74. /**************************************************************************
  75.  InitXLMath()
  76.  =========
  77.  This function registers the task with OPTIMEM and initializes a
  78.  memory pool. Returns TRUE if the memory pool was properly initialized,
  79.  else FALSE. This function must be called in the EXCEL auto_open macro
  80.  along with the EXCEL REGISTER functions.
  81.  
  82.  **************************************************************************/
  83. BOOL FAR PASCAL _export InitXLMath(void)
  84. {
  85.     HANDLE hCurrentTask = GetCurrentTask();
  86.     NPTD pTaskDesc;
  87.  
  88.     // get free task descriptor
  89.     pTaskDesc = GetTaskDescriptor(hCurrentTask);
  90.     return (pTaskDesc != NULL? TRUE : FALSE);
  91. }
  92.  
  93. /**************************************************************************
  94.  ExitXLMath()
  95.  ================
  96.  This function free's the memory allocated to type K ranges and unregisters
  97.  the task with OPTIMEM. This function must be called in the EXCEL auto_close
  98.  macro.
  99.  **************************************************************************/
  100. void FAR PASCAL _export ExitXLMath(void)
  101. {
  102.     HANDLE hCurrentTask = GetCurrentTask();
  103.  
  104.     // free memory used by this task
  105.     ExpungeTaskDescriptor(hCurrentTask);
  106.     CleanMemory();
  107.     return;
  108. }
  109.